package com.qianfeng.zhangwei.sybl.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.widget.RelativeLayout;

import com.qianfeng.zhangwei.sybl.R;
import com.qianfeng.zhangwei.sybl.utils.Utils;

/**
 * welcome界面
 *
 * 实现的两种方式
 * 1>Animation
 * 2>handler
 */
public class SplashActivity extends AppCompatActivity {
    private RelativeLayout layout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        layout = (RelativeLayout) this.findViewById(R.id.splash_bg);
        AnimationSet animationSet = new AnimationSet(true);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.6f, 1.0f);
        animationSet.addAnimation(alphaAnimation);
        animationSet.setDuration(1 * 1000);
        layout.startAnimation(animationSet);
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                startAction();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

    }

    /**
     * 跳转相应的Activity
     */
    public void startAction() {
        Intent intent = new Intent();
        if (Utils.isFirst(this)) {
            intent.setClass(this, MainActivity.class);
        } else {
            intent.setClass(this, GuideActivity.class);
        }
        startActivity(intent);
        this.finish();
    }

}
